package com.css.zfzx.fwsjcj.modules.statistics.fw.controller;

import com.css.bpm.platform.base.response.RestResponse;
import com.css.zfzx.fwsjcj.modules.statistics.fw.service.FwAreaBuildingService;
import com.css.zfzx.fwsjcj.modules.statistics.fw.service.FwDivisionAreaBuildingService;
import com.css.zfzx.fwsjcj.modules.statistics.fw.vo.ProvinceParams;
import com.css.zfzx.fwsjcj.modules.statistics.fw.vo.SelectChinaAndProvinceVo;
import com.css.zfzx.fwsjcj.modules.statistics.fw.vo.SelectStructureVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/fw/division")
@Slf4j
public class FwDivisionAreaBuildingController {

    @Autowired
    private FwDivisionAreaBuildingService fwDivisionAreaBuildingService;

    @Autowired
    private FwAreaBuildingService fwAreaBuildingService;
    /**
     * 查询省相关数据
     * @return
     */
    @GetMapping("/provinceFwData")
    public RestResponse getProvinceFwData(String province) {
        RestResponse restResponse = null;
        try {
            List<SelectChinaAndProvinceVo> list = fwDivisionAreaBuildingService.getProvinceFwData(province);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 获取省的结构类型相关数据
     * @param province
     * @return
     */
    @GetMapping("/provinceStructureData")
    public RestResponse getProvinceStructureData(String province) {
        RestResponse restResponse = null;
        try {
            List<SelectStructureVo> list = fwDivisionAreaBuildingService.getProvinceStructureData(province);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 获取地图上市的相关数据
     * @param province
     * @return
     */
    @GetMapping("/cityFwData")
    public RestResponse getCityFwData(String province) {
        RestResponse restResponse = null;
        try {
            List<SelectChinaAndProvinceVo> list = fwDivisionAreaBuildingService.getCityFwData(province);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 获取省详情页中 对应的市的数据
     * @return
     */
    @GetMapping("/provinceCityFwData")
    public RestResponse getProvinceCityFwData(String province) {
        RestResponse restResponse = null;
        try {
            List<ProvinceParams> list = fwDivisionAreaBuildingService.getProvinceCityFwData(province);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 根据各市更新相关数据
     * @param fwParams
     * @return
     */
    @PostMapping("/updateDataByCity")
    public RestResponse updateDataByCity(@RequestBody ProvinceParams fwParams) {
        RestResponse restResponse = null;
        try {
            String res = fwDivisionAreaBuildingService.updateDataByCity(fwParams);
            restResponse = RestResponse.succeed(res);
        } catch (Exception e) {
            String errormessage = "更新失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }




}
